<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> 
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道名称" prop="channelName">
        <el-input
          v-model="queryParams.channelName"
          placeholder="请输入渠道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册应用" prop="regAppCode">
        <el-input
          v-model="queryParams.regAppCode"
          placeholder="请输入注册应用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="真实姓名" prop="realname">
        <el-input
          v-model="queryParams.realname"
          placeholder="请输入真实姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册ip" prop="regReqIp">
        <el-input
          v-model="queryParams.regReqIp"
          placeholder="请输入注册ip"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已经认证" prop="authFlag">
        <el-input
          v-model="queryParams.authFlag"
          placeholder="请输入是否已经认证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已经人脸" prop="faceFlag">
        <el-input
          v-model="queryParams.faceFlag"
          placeholder="请输入是否已经人脸"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否已上传资质" prop="sourceFlag">
        <el-input
          v-model="queryParams.sourceFlag"
          placeholder="请输入是否已上传资质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-edit" size="small" @click="showDialog = true"
          v-hasPermi="['member:sourceInfo:remove']">重置资质信息</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="baseinfoList" >
      <el-table-column label="用户ID" align="center" prop="uid" />
      <el-table-column label="日期" align="center" prop="dateInfo" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="渠道号" align="center" prop="channelCode" />
      <el-table-column label="渠道名称" align="center" prop="channelName" />
      <el-table-column label="注册应用" align="center" prop="regAppCode" />
      <el-table-column label="用户授信额度" align="center" prop="creditLimitAmount" />
      <el-table-column label="用户名" align="center" prop="username" />
      <el-table-column label="真实姓名" align="center" prop="realname" />
      <el-table-column label="用户类型" align="center" prop="type" />
      <el-table-column label="注册类型" align="center" prop="regType" />
      <el-table-column label="注册ip" align="center" prop="regReqIp" />
      <el-table-column label="用户状态" align="center" prop="status" />
      <el-table-column label="是否已经认证" align="center" prop="authFlag" />
      <el-table-column label="是否已经人脸" align="center" prop="faceFlag" />
      <el-table-column label="是否已上传资质" align="center" prop="sourceFlag" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['member:baseinfo:edit']"
          >修改</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['member:baseinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="输入用户ID" :visible="showDialog" @close="showDialog = false" width="30%">
      <el-input v-model="inputUid" placeholder="请输入用户ID"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showDialog = false">取消</el-button>
        <el-button type="primary" @click="handleDeleteAndUpdate">确认</el-button>
      </div>
    </el-dialog>
   
  </div>
</template>

<script>
import { listBaseinfo, getBaseinfo, delBaseinfo, addBaseinfo, updateBaseinfo } from "@/api/member/baseinfo";
import { delAndupSourceInfo } from "@/api/member/sourceInfo";
export default {
  name: "Baseinfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户基本信息表格数据
      baseinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dateInfo: null,
        mobile: null,
        mobileMd5: null,
        channelCode: null,
        channelName: null,
        regAppCode: null,
        creditLimitAmount: null,
        username: null,
        realname: null,
        idcard: null,
        type: null,
        regType: null,
        regReqIp: null,
        status: null,
        authFlag: null,
        faceFlag: null,
        sourceFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

      }
    };
  },
  mounted() {
    this.baseinfoList = this.baseinfoList.map(item => {
      return { ...item, uid: item.uid.toString() };
    });
  },
  created() {
    this.getList();
  },
  methods: {

        /**删除资质信息 */
        handleDeleteAndUpdate() {
      const uid = this.inputUid.trim();
      this.showDialog = false;
      if (uid) {
        // 调用接口
        delAndupSourceInfo(uid)
          .then(response => {
            this.$message.success("删除成功");
            // 重新刷新列表数据
            this.getList();
          })
          .catch(error => {
            // 处理错误情况
            this.$message.error("删除失败：" + error.message);
          });
      } else {
        this.$message.warning("请输入有效的用户ID");
      }
    },
    /** 查询用户基本信息列表 */
    getList() {
      this.loading = true;
      listBaseinfo(this.queryParams).then(response => {
        this.baseinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uid: null,
        dateInfo: null,
        mobile: null,
        mobileMd5: null,
        channelCode: null,
        channelName: null,
        regAppCode: null,
        creditLimitAmount: null,
        username: null,
        realname: null,
        idcard: null,
        type: null,
        regType: null,
        regReqIp: null,
        status: null,
        authFlag: null,
        faceFlag: null,
        sourceFlag: null,
        deleted: null,
        tenantId: null,
        creator: null,
        updater: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const uid = row.uid || this.ids
      getBaseinfo(uid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.uid != null) {
            updateBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uids = row.uid || this.ids;
      this.$modal.confirm('是否确认删除用户基本信息编号为"' + uids + '"的数据项？').then(function() {
        return delBaseinfo(uids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('member/baseinfo/export', {
        ...this.queryParams
      }, `baseinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
